#! /bin/bash
WORK_PATH="/home/cicd/docker_webhook/cicd-front"
TIMENOW=$(date '+%Y%m%d%H%M%S')
cd $WORK_PATH
echo "clean old code..."
git reset --hard origin/master
git clean -f
echo "pull latest code..."
git pull origin master
echo "bundle latest code..."
rm -rf node_modules
npm config set registry https://registry.npm.taobao.org
npm install
npm run build
echo "start build..."
docker build -t cicd-front:v${TIMENOW} . 
echo "stop and destroy old container..."
docker stop cicd-front-container
docker rm cicd-front-container
echo "start new container..."
docker container run -p 8081:80 --name cicd-front-container -d cicd-front:v${TIMENOW}
